<template>
  <el-menu
    default-active="1-4-1"
    class="el-menu-vertical-demo"
    background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
    @open="handleOpen"
    @close="handleClose"
    :collapse="isCollapse"
  >
    <h3>服装店销售管理系统</h3>
    <el-menu-item @click="clickMenu(item)"
      v-for="item in noChildren"
      :index="item.path"
      :key="item.path"
    >
      <i :class="'el-icon-' + item.icon"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>
    <el-submenu v-for="item in hasChildren" :index="item.path" :key="item.path">
      <template slot="title">
        <i :class="'el-icon-' + item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </template>
      <el-menu-item-group 
        v-for="(subItem, subIndex) in item.children"
        :key="subItem.path"
      >
        <el-menu-item @click="clickMenuItem(subItem)" :index="subIndex">
          {{ subItem.label }}
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>

<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-menu{
  height: 100%;
  border: none;
  h3 {
    color:#f5f6fa ;
    text-align:center;
    line-height:48px

  }
}
</style>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      menu: [
        {
          path: "/",
          name: "home",
          label: "首页",
          icon: "s-home",
          url: "Home/Home",
        },
        {
          path: "/clothes",
          name: "Clothes",
          label: "商品管理",
          icon: "s-shop",
          url: "ClothesManage/ClothesManage",
        },
        {
          path: "/order",
          name: "order",
          label: "订单管理",
          icon: "s-goods",
          url: "OrderManage/OrderManage",
        },
        {
          path: "/inventory",
          name: "inventory",
          label: "库存管理",
          icon: "truck",
          url: "InventoryManage/InventoryManage",
        },
        {
          path: "/report",
          name: "report",
          label: "报表管理",
          icon: "truck",
          url: "ReportManage/ReportManage",
        },
        {
          path: "/users",
          name: "users",
          label: "用户管理",
          icon: "s-goods",
          url: "UsersManage/UsersManage",
        },
        {
          path: "/other",
          name: "other",
          label: "其他",
          icon: "location",
          children: [
            {
              path: "/discount",
              name: "discount",
              label: "折扣设置",
              icon: "setting",
              url: "Other/DiscountManage",
            },
            {
              path: "/login",
              name: "login",
              label: "切换账号",
              icon: "setting",
              url: "/Other/PageTwo",
            },
          ],
        },
      ],
    };
  },
  methods: {
      open() {
        this.$confirm(' 确认退出登录?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$router.push('/');
          this.$message({
            type: 'success',
            message: '退出登录成功!'
           
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出！'
          });          
        });
      },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    clickMenu(item){
      this.$router.push({
        name: item.name
      })
    },
    clickMenuItem(subItem){
      this.$router.push({
        name: subItem.name
      })
    }
  },
  computed: {
    noChildren() {
      return this.menu.filter((item) => !item.children);
    },
    hasChildren() {
      return this.menu.filter((item) => item.children);
    },
  },
};
</script>
